from apps import db
from datetime import datetime, timezone
import datetime as dt

class reportRecord(db.Model):
    __tablename__ = 'report_record'
    
    id = db.Column(db.Integer, primary_key=True)
    run_id = db.Column(db.String(64),nullable=False,comment='分析编号')
    sample_1 = db.Column(db.String(64),nullable=False,comment='样品1名称')
    sample_2 = db.Column(db.String(64),nullable=False,comment='样品2名称')
    timestamp = db.Column(db.String(128),nullable=False,comment='时间戳')
    reportTmp = db.Column(db.String(128),nullable=False,comment='模板版本')
    run_at = db.Column(db.String(128),nullable=False,comment='分析时间')
    created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc))
    updated_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc),
    onupdate=lambda:datetime.now(timezone.utc))
    def to_dict(self):
        result = {}
        for c in self.__table__.columns:
            value = getattr(self, c.name)
            if isinstance(value, dt.datetime):
                value = value.strftime('%Y-%m-%d %H:%M:%S')
            elif isinstance(value, dt.date):
                value = value.strftime('%Y-%m-%d')
            result[c.name] = value
        return result
